// 因素
import axios from '../../resource'

const state = {
  questionList: []
}


const mutations = {
  setQuestionList (state, params) {
    state.questionList = params;
  }
}


const actions = {
  // 题库列表
  index ({state, commit, dispatch}) {
    commit('setLoading', true, { root: true });
    axios({
      url: '/api/questions'
    }).then(response => {
      commit('setLoading', false, { root: true });
      commit('setQuestionList', response)
    })
  },

  // 题库修改
  update ({state, commit, dispatch}, questionId, params) {
    axios({
      url: `/api/questions/${questionId}`,
      data: params,
      method: 'POST'
    }).then(response => {
      dispatch('index')
    })
  },

  // 题库禁用
  delete ({state, commit, dispatch}, questionId) {
    axios({
      url: `/api/questions/`,
      data: {'questionId': questionId},
    }).then(response => {
      dispatch('index')
    })
  }


}


export default {
  namespaced: true,
  state,
  actions,
  mutations
}
